// Author: 		ngohaibac@hocdelam.org
// Date:		23rd Sep, 2009
// Hardware:	TMS320F28335
// Module:		Serial Communication Interface (SCI) 

/*
 * UART_Init(SCIC,115200);
 * UART_setRxFifoLevel(SCIC,8);
 * UART_InitInt(SCIC,&Scic_RX_Isr);
 */

#ifndef DSP2833X_SCILIB_H_
#define DSP2833X_SCILIB_H_

// Define CPU Freq
#if CPU_FRQ_150MHZ
	#define CPU_FREQ 	 150E6
#endif
#if CPU_FRQ_100MHZ
	#define CPU_FREQ 	 100E6
#endif
#define LSPCLK_FREQ  CPU_FREQ/4

// SCI Ports
enum SciPorts {SCIA, SCIB, SCIC};

//volatile struct EPWM_REGS *ePWM[] =
// 			 { &EPwm1Regs,	&EPwm1Regs,	&EPwm2Regs,	&EPwm3Regs,	&EPwm4Regs,	&EPwm5Regs,	&EPwm6Regs};


/*
struct buffer{
	Uint16 *start;
	int offset;
	int length;
};
*/

// Declare some functions

// Initialize module
void SCI_Init(enum SciPorts port, Uint64 BaudRate);				// FIFO generate Interrupt after 8
void SCI_setRxFifoLevel(enum SciPorts port,Uint16 RxFifoLevel);
void SCI_InitInt(enum SciPorts port,PINT RxIntFcn);

// Read and write data
Uint16 SCI_Read(enum SciPorts port); 
void SCI_Write(enum SciPorts port,Uint16 SCI_Data);
//void SCI_PrString(enum SciPorts port,Uint16 * buffer, Uint16 len);
void SCI_PrString(enum SciPorts port,char* str);

void SCI_PrHex(enum SciPorts port, Uint16 hex_data,Uint16 number_of_digit);
void SCI_PrDec(enum SciPorts port, Uint16 hex_data,Uint16 number_of_digit);
// Buffer
Uint16 SCI_getRxBufferSize(enum SciPorts port);

// Clear Interrupt flags
void SCI_clearIntFlags(enum SciPorts port);


#endif /*DSP2833X_SCILIB_H_*/
